package com.qingke.ssh.control;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.qingke.ssh.bean.Employee;
import com.qingke.ssh.bean.EmployeeLogin;
import com.qingke.ssh.bean.EmployeeType;
import com.qingke.ssh.dao.EmployeeDao;
import com.qingke.ssh.service.EmployeeService;

@Controller
public class AddEmployee extends ActionSupport {
	@Autowired
	private Employee employee;
	@Autowired
	private EmployeeType employeeType;
	@Autowired
	private EmployeeLogin employeeLogin;

	@Autowired
	private EmployeeService employeeService;

	@Autowired
	private EmployeeDao dao;

	private String name;
	private String phone;
	private String mail;
	private Date date = new Date();
	private String selectType;

	public String getName() {
		return name;
	}

	public String getPhone() {
		return phone;
	}

	public String getMail() {
		return mail;
	}

	public Date getDate() {
		return date;
	}

	public String getSelectType() {
		return selectType;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public void setMail(String mail) {
		this.mail = mail;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public void setSelectType(String selectType) {
		this.selectType = selectType;
	}

	public Employee getEmployee() {
		return employee;
	}

	public EmployeeType getEmployeeType() {
		return employeeType;
	}

	public EmployeeLogin getEmployeeLogin() {
		return employeeLogin;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	public void setEmployeeType(EmployeeType employeeType) {
		this.employeeType = employeeType;
	}

	public void setEmployeeLogin(EmployeeLogin employeeLogin) {
		this.employeeLogin = employeeLogin;
	}

	@Override
	public String execute() throws Exception {

		employeeType.setId(Integer.valueOf(selectType));
		employee.setName(name);
		employee.setPhone(phone);
		employee.setMail(mail);
		employee.setHiredate(date);
		employee.setEmployeeType(employeeType);

		employeeLogin.setEmployee(employee);
		employeeLogin.setCode(phone);
		employeeLogin.setPassword("123456");

		employeeService.add(employee, employeeLogin);
		return "success";
	}

}
